package com.steven.treatment_case.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.steven.treatment_case.R;
import com.steven.treatment_case.entity.HSBedEntity;

import java.util.List;

public class TestAdapter extends RecyclerView.Adapter<TestAdapter.MyHolder> {

    private Context context;
    private List<HSBedEntity> flashlyBeans;
    private flashCallBack mCallBack;

    public TestAdapter(Context context, List<HSBedEntity> flashlyBeans, flashCallBack mCallBack) {
        this.context = context;
        this.flashlyBeans = flashlyBeans;
        this.mCallBack = mCallBack;
    }

    @Override
    public MyHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.item_hs_bed, null);
        return new MyHolder(view);
    }

    @Override
    public void onBindViewHolder(MyHolder holder, int position) {
        HSBedEntity item = flashlyBeans.get(position);

        holder.tv_title.setText(item.getHsBed());
        holder.tv_name.setText(item.getName());
        holder.tv_sex.setText(item.getSex());
        holder.tv_age.setText(item.getAge());
        holder.tv_birth.setText(item.getBirthDate());
        holder.tv_admissionTime.setText(item.getAdmissionTime());
        holder.tv_case.setText(item.getCaseHS());

        if (mCallBack != null) {
            holder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int index = (int) v.getTag();
                    mCallBack.onItemClick(index);
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return flashlyBeans.size();
    }

    class MyHolder extends RecyclerView.ViewHolder {
//        @BindView(R.id.tv_title)
        TextView tv_title;
//        @BindView(R.id.tv_name)
        TextView tv_name;
//        @BindView(R.id.tv_sex)
        TextView tv_sex;
//        @BindView(R.id.tv_age)
        TextView tv_age;
//        @BindView(R.id.tv_birth)
        TextView tv_birth;
//        @BindView(R.id.tv_admissionTime)
        TextView tv_admissionTime;
//        @BindView(R.id.tv_case)
        TextView tv_case;


        MyHolder(View itemView) {
            super(itemView);
//            ButterKnife.bind(this, itemView);
             tv_title = itemView.findViewById(R.id.tv_title);//床位
             tv_name =itemView.findViewById(R.id.tv_name);//姓名
             tv_sex = itemView.findViewById(R.id.tv_sex);//性别
             tv_age = itemView.findViewById(R.id.tv_age);//年龄
             tv_birth = itemView.findViewById(R.id.tv_birth);//出生日期
             tv_admissionTime =itemView.findViewById(R.id.tv_admissionTime);//入院时间
             tv_case =itemView.findViewById(R.id.tv_case);//病例
        }
    }

    public interface flashCallBack {
        void onItemClick(int position);
    }
}
